package com.panku.service.impl;

import com.panku.common.Utils.SysUtil;
import com.panku.common.exception.BizException;
import com.panku.common.vo.Result;
import com.panku.dao.OrderDao;
import com.panku.entity.Order;
import com.panku.entity.Product;
import com.panku.entity.User;
import com.panku.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: jack
 * @Description:
 * @Date Create in 8:35 2021-02-02
 **/
@Service
public class OrderService implements IOrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public void saveOrder(Integer uid, Integer pid, Integer nums) {
        //根据产品id获取产品信息
        Product product = restTemplate.postForObject("http://127.0.0.1:8081/product/get/" + pid, null, Product.class);
        Order order = new Order(uid, pid, product.getPprice(), nums);
        orderDao.save(order);

    }

    @Override
    public Order get(Long oid) {
        return orderDao.findById(oid).get();
    }
}
